package com.typy.www.tpay.ui.acitivity;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.TypeReference;
import com.nostra13.universalimageloader.utils.L;
import com.typy.www.tpay.R;
import com.typy.www.tpay.base.BaseBackActivity;
import com.typy.www.tpay.bean.bean.BaseReturn;
import com.typy.www.tpay.bean.listvm.ActivicationListVm;
import com.typy.www.tpay.bean.listvm.NoticeListVm;
import com.typy.www.tpay.bean.vm.ActivicationVm;
import com.typy.www.tpay.bean.vm.NoticeVm;
import com.typy.www.tpay.constance.Constance;
import com.typy.www.tpay.constance.MessageEvent;
import com.typy.www.tpay.ui.adapter.NoticeAdapter;
import com.typy.www.tpay.ui.adapter.RecordAdapter;
import com.typy.www.tpay.ui.prt.PtrListContent;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.GsonUtils;
import com.typy.www.tpay.util.Logutil;
import com.typy.www.tpay.util.MessageAction;
import com.typy.www.tpay.util.ParamsUtil;
import com.typy.www.tpay.util.PopupUtil;
import com.typy.www.tpay.util.UiHelper;
import com.typy.www.tpay.util.UpdataUiUtil;
import com.typy.www.tpay.util.listviewanimations.IntentUtil;
import com.typy.www.tpay.volley.HTTPUtils;
import com.typy.www.tpay.volley.VolleyListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 13799 on 2018/6/27.
 */

public class RecordActivity extends BaseBackActivity implements View.OnClickListener {

    //里面懒得改，基本一样，想改的可以自己改
    private int classType = 0;
    private PtrListContent ptrListContent;
    private ListView mListView;
    private RecordAdapter adapter;
    private ActivicationListVm mListVm;
    private List<ActivicationVm> mData = new ArrayList<>();
    private String billName;
    private TextView tvSell;
    private TextView tvBuy;
    private boolean mIsBuy = false;
    private boolean isFirst=true;

    public static void show(Context context, int classType) {
        Intent intent = new Intent();
        intent.putExtra("classType", classType);
        IntentUtil.intent2Activity(context, intent, RecordActivity.class);
    }

    public static void show(Context context, int classType, String billName) {
        Intent intent = new Intent();
        intent.putExtra("classType", classType);
        intent.putExtra("billName", billName);
        IntentUtil.intent2Activity(context, intent, RecordActivity.class);
    }

    @Override
    protected View getContentView() {
        ptrListContent = new PtrListContent(getActivity()) {
            @Override
            protected void getPage(int pageIndex, boolean refresh) {
                pageControl(pageIndex, refresh);
            }
        };
        return ptrListContent.getmView();
    }

    @Override
    protected void initView() {
        super.initView();
        EventBus.getDefault().register(this);
        classType = getIntent().getIntExtra("classType", 0);
        billName = getIntent().getStringExtra("billName");
        setTitle(ClassHoldUtil.getClassTitle(classType));
        initAdapter();
        dateControl();
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void MessageEventBus(MessageEvent msg) {
        if (msg.getKey().equals(MessageAction.CANCELORDER)) {
            getCancelorderDate(msg.getMessage());
        }else if (msg.getKey().equals(MessageAction.CLOSERECORD)) {
            Logutil.print("FINISH");
            finish();
        }else if(msg.getKey().equals(MessageAction.REFEFRESHTOUSU)){
            dateControl();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(isFirst){
            isFirst=false;
        }else if(classType==ClassHoldUtil.QUERENGDAKUANB||classType==ClassHoldUtil.QUERENGDAKUANS){
            UiHelper.showLoading(getActivity());
            dateControl();
        }
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    private void initAdapter() {
        mListView = ptrListContent.getListView();
        adapter = new RecordAdapter(getActivity());
        if(classType==ClassHoldUtil.DIGIDINGDANG)
            classType=ClassHoldUtil.DIGIDINGDANGNOW;
        adapter.setClassType(classType);
        View head = LayoutInflater.from(getActivity()).inflate(R.layout.head_record, null);
        View head2 = LayoutInflater.from(getActivity()).inflate(R.layout.foot_zpay, null);
        if (classType == ClassHoldUtil.AmountListRecord || classType == ClassHoldUtil.SharePointRecord ||
                classType == ClassHoldUtil.PointRecord || classType == ClassHoldUtil.ExchangePointRecord ||
                classType == ClassHoldUtil.ICO||classType==ClassHoldUtil.BUYINCORECORD||classType==ClassHoldUtil.SELLOUTRECORD) {
            if (classType == ClassHoldUtil.ExchangePointRecord) {
                UpdataUiUtil.getDefaul().setText("余额", (TextView) head.findViewById(R.id.tv_type))
                        .setText("积分兑换", (TextView) head.findViewById(R.id.tv_amount));
            } else if (classType == ClassHoldUtil.ICO) {
                UpdataUiUtil.getDefaul().setText("数量", (TextView) head.findViewById(R.id.tv_type))
                        .setText("金额", (TextView) head.findViewById(R.id.tv_amount));
            }else if (classType==ClassHoldUtil.SELLOUTRECORD||
                    classType==ClassHoldUtil.SELLYIWANCHENG||classType==ClassHoldUtil.BUYYIWANCHENG) {
                UpdataUiUtil.getDefaul().setText("卖出金额", (TextView) head.findViewById(R.id.tv_type))
                        .setText("余额", (TextView) head.findViewById(R.id.tv_amount))
                        .setText("卖出时间", (TextView) head.findViewById(R.id.tv_time));
            }else if (classType==ClassHoldUtil.BUYINCORECORD
                    ) {
                UpdataUiUtil.getDefaul().setText("买入余额", (TextView) head.findViewById(R.id.tv_type))
                        .setText("卖家UID", (TextView) head.findViewById(R.id.tv_amount))
                        .setText("买入时间", (TextView) head.findViewById(R.id.tv_time));
            }

            mListView.addHeaderView(head);
        } else if (classType==ClassHoldUtil.DIGIDINGDANGNOW||classType==ClassHoldUtil.DIGIDINGDANGEND) {
            tvSell = (TextView) head2.findViewById(R.id.tv_sell);
            tvBuy = (TextView) head2.findViewById(R.id.tv_buy);
            UpdataUiUtil.getDefaul().setText("出售中", tvSell)
                    .setText("已完成", tvBuy);
            mListView.addHeaderView(head2);
            tvBuy.setOnClickListener(this);
            tvSell.setOnClickListener(this);
            updateFoot(mIsBuy);
        }
        mListView.setAdapter(adapter);
    }

    private void updateFoot(boolean isBuy) {
        if (isBuy) {
            tvBuy.setTextColor(getResources().getColor(R.color.text_blue));
            tvSell.setTextColor(getResources().getColor(R.color.text_darkcolor));
            if (mIsBuy != isBuy) {
                classType=ClassHoldUtil.DIGIDINGDANGEND;
                adapter.setClassType(classType);
                getMyordernowData(1, true, isBuy);
                mIsBuy = isBuy;
            }
        } else {
            tvSell.setTextColor(getResources().getColor(R.color.text_blue));
            tvBuy.setTextColor(getResources().getColor(R.color.text_darkcolor));
            if (mIsBuy != isBuy) {
                classType=ClassHoldUtil.DIGIDINGDANGNOW;
                adapter.setClassType(classType);
                getMyordernowData(1, true, isBuy);
                mIsBuy = isBuy;
            }
        }
    }

    private void dateControl() {
        if (classType == ClassHoldUtil.AmountListRecord) {
            getAmountlistDate(1, false);
        } else if (classType == ClassHoldUtil.SharePointRecord) {
            getSharepointlistDate(1, false);
        } else if (classType == ClassHoldUtil.PointRecord) {
            getPointlistDate(1, false);
        } else if (classType == ClassHoldUtil.ActivicationRecord) {
            getActivicationDate(1, false);
        } else if (classType == ClassHoldUtil.ExchangePointRecord) {
            getExchangelistDate(1, false);
        } else if (classType == ClassHoldUtil.TurnOutRecord) {
            getTurnOutDate(1, false);
        } else if (classType == ClassHoldUtil.ChangeIntoRecord) {
            getTurnInDate(1, false);
        } else if (classType == ClassHoldUtil.ShareRecord) {
            getSharelistDate(1, false);
        } else if (classType == ClassHoldUtil.SuggestRecord) {
            getSuggestData(1, false);
        } else if (classType == ClassHoldUtil.TurnOutDigiRECORD) {
            getIcoturnoutlistData(1, false);
        } else if (classType == ClassHoldUtil.DigiDetail) {
            getMybillData(1, false);
        } else if (classType == ClassHoldUtil.ICO) {
            getBuyicolistData(1, false);
        } else if (classType==ClassHoldUtil.DIGIDINGDANGNOW||classType==ClassHoldUtil.DIGIDINGDANGEND) {
            getMyordernowData(1, true, mIsBuy);
        }else if (classType==ClassHoldUtil.BUYINCORECORD||classType==ClassHoldUtil.SELLOUTRECORD) {
            getBuyrecordlistData(1, true);
        }else if (classType==ClassHoldUtil.BUYYIWANCHENG||classType==ClassHoldUtil.SELLYIWANCHENG) {
            getBuyfinishlistData(1, true);
        }else if (classType==ClassHoldUtil.QUERENGDAKUANB||classType==ClassHoldUtil.QUERENGDAKUANS) {
            getSurepaylistURLData(1, true);
        }
    }

    private void pageControl(int page, boolean refresh) {
        if (classType == ClassHoldUtil.AmountListRecord) {
            getAmountlistDate(page, refresh);
        } else if (classType == ClassHoldUtil.SharePointRecord) {
            getSharepointlistDate(page, refresh);
        } else if (classType == ClassHoldUtil.PointRecord) {
            getPointlistDate(page, refresh);
        } else if (classType == ClassHoldUtil.ActivicationRecord) {
            getActivicationDate(page, refresh);
        } else if (classType == ClassHoldUtil.ExchangePointRecord) {
            getExchangelistDate(page, refresh);
        } else if (classType == ClassHoldUtil.TurnOutRecord) {
            getTurnOutDate(page, refresh);
        } else if (classType == ClassHoldUtil.ChangeIntoRecord) {
            getTurnInDate(page, refresh);
        } else if (classType == ClassHoldUtil.ShareRecord) {
            getSharelistDate(page, refresh);
        } else if (classType == ClassHoldUtil.SuggestRecord) {
            getSuggestData(page, refresh);
        } else if (classType == ClassHoldUtil.TurnOutDigiRECORD) {
            getIcoturnoutlistData(page, refresh);
        } else if (classType == ClassHoldUtil.DigiDetail) {
            getMybillData(page, refresh);
        } else if (classType == ClassHoldUtil.ICO) {
            getBuyicolistData(page, refresh);
        } else if (classType==ClassHoldUtil.DIGIDINGDANGNOW||classType==ClassHoldUtil.DIGIDINGDANGEND) {
            getMyordernowData(page, true, mIsBuy);
        }else if ( classType==ClassHoldUtil.BUYINCORECORD||classType==ClassHoldUtil.SELLOUTRECORD) {
            getBuyrecordlistData(page, true);
        }else if ( classType==ClassHoldUtil.BUYYIWANCHENG||classType==ClassHoldUtil.SELLYIWANCHENG) {
            getBuyfinishlistData(page, true);
        }else if (classType==ClassHoldUtil.QUERENGDAKUANB||classType==ClassHoldUtil.QUERENGDAKUANS) {
            getSurepaylistURLData(page, true);
        }
    }

    //激活记录
    private void getActivicationDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getActivelistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    //转出记录
    private void getTurnOutDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getTurnoutlistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    //转入记录
    private void getTurnInDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getTurninlistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    //余额记录
    private void getAmountlistDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getAmountlistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSONF(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});

                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
//                    ActivicationListVm v= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
//                    for(ActivicationVm vm:v.getData()){
//                        Logutil.print("mListvm=="+vm.getFdAmount());
//                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    //积分记录
    private void getPointlistDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getPointlistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    //分享分
    private void getSharepointlistDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);
        HTTPUtils.post(getActivity(), Constance.getSharepointlistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }//分享分

    private void getExchangelistDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);
        HTTPUtils.post(getActivity(), Constance.getExchangelistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }//分享分

    private void getSharelistDate(final int page, final boolean refresh) {
        ParamsUtil params = new ParamsUtil();
        params.put("pageNum", page);
        params.put("pageSize", Constance.LIMT);
        HTTPUtils.post(getActivity(), Constance.getSharelistURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getSuggestData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getReplaylistURL(), paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getIcoturnoutlistData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);

        HTTPUtils.post(getActivity(), Constance.getIcoturnoutlistURL(), paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    } else {
                        UiHelper.showToast(getActivity(), "暂无数据");
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getMybillData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
        paramsUtil.put("fdIconTypeName", billName);
//        paramsUtil.put("fdIconTypeName", 1);

        HTTPUtils.post(getActivity(), Constance.getMybillURL(), paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getBuyicolistData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
//        paramsUtil.put("fdIconTypeName",billName);

        HTTPUtils.post(getActivity(), Constance.getBuyicolistURL(), paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0)
                        mData.clear();
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getMyordernowData(final int page, final boolean refresh, boolean mIsBuy) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
        String url = "";
        if (mIsBuy)
            url = Constance.getMyorderfinishURL();
        else
            url = Constance.getMyordernowURL();

        HTTPUtils.post(getActivity(), url, paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0) {
                        mData.clear();
                        adapter.notifyDataSetChanged();
                    }
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);

                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_sell:
                updateFoot(false);
                break;
            case R.id.tv_buy:
                updateFoot(true);
                break;

        }
    }
    //转出记录
    private void getCancelorderDate(String fdId) {
        ParamsUtil params = new ParamsUtil();
        params.put("fdId", fdId);

        HTTPUtils.post(getActivity(), Constance.getCancelorderURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                  UiHelper.showToast(getActivity(),"取消成功");
                    getMyordernowData(1, true, mIsBuy);
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    private void getBuyrecordlistData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
        String url = "";
        if (classType==ClassHoldUtil.BUYINCORECORD)
            url = Constance.getBuyrecordlistURL();
        else
            url = Constance.getSellerrecordlistURL();

        HTTPUtils.post(getActivity(), url, paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0) {
                        mData.clear();
                        adapter.notifyDataSetChanged();
                    }
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }private void getBuyfinishlistData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
        String url = "";
        if (classType==ClassHoldUtil.BUYYIWANCHENG)
            url = Constance.getBuyfinishlistURL();
        else
            url = Constance.getSellerfinishlistURL();

        HTTPUtils.post(getActivity(), url, paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0) {
                        mData.clear();
                        adapter.notifyDataSetChanged();
                    }
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }private void getSurepaylistURLData(final int page, final boolean refresh) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("pageNum", page);
        paramsUtil.put("pageSize", Constance.LIMT);
        String url = "";
        if (classType==ClassHoldUtil.QUERENGDAKUANB)
            url = Constance.getSurepaylistURL();
        else
            url = Constance.getWillsurereceivelistURL();
        HTTPUtils.post(getActivity(), url, paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                UiHelper.hideLoading();
                if (ret.getCode() == 200 && ret.getData() != null) {
                    if (refresh || page == 0) {
                        mData.clear();
                        adapter.notifyDataSetChanged();
                    }
//                    mListVm = GsonUtils.parseJSON(ret.getData().toString(), ActivicationListVm.class);
                    mListVm= com.alibaba.fastjson.JSONObject.parseObject(ret.getData().toString(),new TypeReference<ActivicationListVm>(){});
                    if (mListVm != null && mListVm.getData() != null && mListVm.getData().size() != 0) {
                        mData.addAll(mListVm.getData());
                        adapter.setData(mData);
                        adapter.notifyDataSetChanged();
                    }
                }
                ptrListContent.loadInitialPage(mListVm.getCount());
            }

            @Override
            public void onResponseErr(int code, String msg) {
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }
}
